/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.vo.EstateBuildingDeptVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.admin.entity.EstateBuilding;
import org.springblade.modules.admin.vo.EstateBuildingVO;
import org.springblade.modules.admin.service.IEstateBuildingService;
import org.springblade.core.boot.ctrl.BladeController;

import java.util.List;
import java.util.Map;

/**
 * 物业项目表 控制器
 *
 * @author ysq
 * @since 2022-05-27
 */
@RestController
@AllArgsConstructor
@RequestMapping("admin/estate/building")
@Api(value = "物业项目表", tags = "物业项目表接口")
public class EstateBuildingController extends BladeController {

	private final IEstateBuildingService estateBuildingService;


	/**
	 * 自定义分页 物业项目表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "分页")
	public R<IPage<EstateBuildingVO>> page(EstateBuildingVO estateBuilding, Query query) {
		IPage<EstateBuildingVO> pages = estateBuildingService.selectEstateBuildingPage(Condition.getPage(query), estateBuilding);
		return R.data(pages);
	}

	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情")
	public R<EstateBuildingVO> detail(@ApiParam(value = "主键集合", required = true) @RequestParam Long id) {
		return R.data(estateBuildingService.detail(id));
	}

	/**
	 * 新增 物业项目表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "新增", notes = "传入estateBuilding")
	public R save(@Valid @RequestBody EstateBuilding estateBuilding) {
		return R.status(estateBuildingService.save(estateBuilding));
	}

	/**
	 * 批量归档/还原
	 */
	@PostMapping("/batch/status")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "批量归档/还原")
	public R batchStatus(@ApiParam(value = "主键集合", required = true) @RequestParam String ids,
					@ApiParam(value = "状态 0-归档, 1-正常", required = true) @RequestParam Integer status) {
		return R.status(estateBuildingService.batchStatus(Func.toLongList(ids), status));
	}

	@GetMapping("/select/name")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "项目名称下拉选择数据")
	public R<List<Map<String, Object>>> selectName() {
		return R.data(estateBuildingService.selectName());
	}

	@GetMapping("/select/dept")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "所属机构下拉选择数据")
	public R<List<Map<String, Object>>> selectDept() {
		return R.data(estateBuildingService.selectDept());
	}

	@GetMapping("/select/dept/by/building/ids")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "根据项目id获取项目所属机构")
	public R<List<EstateBuildingDeptVO>> selectDeptByBuildingIds(@ApiParam(value = "项目id，多个逗号隔开", required = true) @RequestParam String buildingIds) {
		return R.data(estateBuildingService.selectDeptByBuildingIds(buildingIds));
	}

	/**
	 * 批量分配机构
	 */
	@PostMapping("/batch/dept")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "批量分配机构")
	public R batchDept(@ApiParam(value = "主键集合", required = true) @RequestParam String ids,
						 @ApiParam(value = "机构id", required = true) @RequestParam Long deptId) {
		return R.status(estateBuildingService.batchDept(Func.toLongList(ids), deptId));
	}

	@GetMapping("/check/dept")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "分配机构检验提示")
	public R checkDept(@ApiParam(value = "主键集合", required = true) @RequestParam String ids,
					   @ApiParam(value = "机构id", required = true) @RequestParam Long deptId) {
		return R.data(estateBuildingService.checkDept(Func.toLongList(ids), deptId));
	}

}
